﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefMachine" :model="stateMachine.vmModel" label-width="100px">
    <div>{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_StationCodeId_FormItem" prop="LinkedVM.StationCodeId" :label="$t('message.autotrans._Model_Machine_StationCode')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_StationCode')}), trigger: 'blur' }]" >
          <el-select v-model="stateMachine.vmModel.LinkedVM.StationCodeId" clearable>
             <el-option v-for="item in stateMachine.AllStationCodes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_MachineName_FormItem" prop="LinkedVM.MachineName" :label="$t('message.autotrans._Model_Machine_MachineName')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_MachineName')}), trigger: 'blur' }]" >
          <el-input v-model="stateMachine.vmModel.LinkedVM.MachineName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Asset_FormItem" prop="LinkedVM.Asset" :label="$t('message.autotrans._Model_Machine_Asset')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_Asset')}), trigger: 'blur' }]" >
          <el-input v-model="stateMachine.vmModel.LinkedVM.Asset" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_RatedPower_FormItem" prop="LinkedVM.RatedPower" :label="$t('message.autotrans._Model_Machine_RatedPower')">
          <el-input v-model="stateMachine.vmModel.LinkedVM.RatedPower" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_PersonCode_FormItem" prop="LinkedVM.PersonCode" :label="$t('message.autotrans._Model_Machine_PersonCode')">
          <el-input v-model="stateMachine.vmModel.LinkedVM.PersonCode" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_MachineStatus_FormItem" prop="LinkedVM.MachineStatus" :label="$t('message.autotrans._Model_Machine_MachineStatus')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_MachineStatus')}), trigger: 'blur' }]" >
          <el-select v-model="stateMachine.vmModel.LinkedVM.MachineStatus" clearable>
             <el-option key="NORMAL" value="NORMAL" :label="$t('message.autotrans._Enum_EquipmentStatus_NORMAL')"></el-option>
             <el-option key="FREE" value="FREE" :label="$t('message.autotrans._Enum_EquipmentStatus_FREE')"></el-option>
             <el-option key="MAINTAIN" value="MAINTAIN" :label="$t('message.autotrans._Enum_EquipmentStatus_MAINTAIN')"></el-option>
             <el-option key="OFFLINE" value="OFFLINE" :label="$t('message.autotrans._Enum_EquipmentStatus_OFFLINE')"></el-option>
             <el-option key="REPAIR" value="REPAIR" :label="$t('message.autotrans._Enum_EquipmentStatus_REPAIR')"></el-option>
             <el-option key="SCRAP" value="SCRAP" :label="$t('message.autotrans._Enum_EquipmentStatus_SCRAP')"></el-option>
             <el-option key="ON_MACHINE" value="ON_MACHINE" :label="$t('message.autotrans._Enum_EquipmentStatus_ON_MACHINE')"></el-option>
             <el-option key="IN_LIBRARY" value="IN_LIBRARY" :label="$t('message.autotrans._Enum_EquipmentStatus_IN_LIBRARY')"></el-option>
             <el-option key="IN_MAINTAIN" value="IN_MAINTAIN" :label="$t('message.autotrans._Enum_EquipmentStatus_IN_MAINTAIN')"></el-option>
             <el-option key="OVERHAUL" value="OVERHAUL" :label="$t('message.autotrans._Enum_EquipmentStatus_OVERHAUL')"></el-option>
             <el-option key="CH_M_AND_T" value="CH_M_AND_T" :label="$t('message.autotrans._Enum_EquipmentStatus_CH_M_AND_T')"></el-option>
             <el-option key="FAULT" value="FAULT" :label="$t('message.autotrans._Enum_EquipmentStatus_FAULT')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitMachine"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onCloseMachine"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageBaseInformationMachineBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { machineApi } from '/@/api/baseinformation/machine';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMachine = ref();
const stateMachine = reactive({
    vmModel: {
	  LinkedVM:{
        StationCodeId: null,
        MachineName: '',
        Asset: '',
        PersonCode: '',
        MachineStatus: undefined,
      },
      Ids:[],
      
	},
    
    AllStationCodes: [] as any[],
});

// 取消
const onCloseMachine = () => {
    closeDialog();
};

// 提交
const onSubmitMachine = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefMachine.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            machineApi().batchedit(stateMachine.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
	})
};


// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/BaseInformation/Machine/GetStations',[],false).then(x=>{stateMachine.AllStationCodes = x});
    if (ci.attrs["wtmdata"]) {
		stateMachine.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateMachine.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

